package leetcode;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-6-19
 * Time: 上午9:43
 * To change this template use File | Settings | File Templates.
 */
public class Swap_Nodes_in_Pairs {
    public ListNode swapPairs(ListNode head) {
        ListNode h1 = new ListNode(0);
        h1.next = head;
        ListNode last = h1;
        ListNode current = head;
        while(current!=null){
            if(current.next!=null){
                ListNode tmp = current.next;
                current.next = tmp.next;
                tmp.next = current;
                last.next = tmp;
                last = current;
                current = current.next;
            }
            else
                current = current.next;
        }
        return h1.next;
    }
    public static void main(String[] args){
        Swap_Nodes_in_Pairs swap_nodes_in_pairs = new Swap_Nodes_in_Pairs();
        ListNode head = null;
        ListNode hh = swap_nodes_in_pairs.swapPairs(head);
        while(hh!=null){
            System.out.print(hh.val+" ");
            hh = hh.next;
        }
    }
}
